//
//  KKDataBaseManager.h
//  FreightAssistant
//
//  Created by leo on 15/11/9.
//  Copyright © 2015年 leo. All rights reserved.
//

#import <Foundation/Foundation.h>

static NSString *KKDataBase_TableName_EmployeeInfo = @"tab_employee";
static NSString *KKDataBase_TableName_CustomerInfo = @"tab_customer";
static NSString *KKDataBase_TableName_GoodsInfo = @"tab_goods";
static NSString *KKDataBase_TableName_GoodsCategory = @"tab_category";


typedef void(^KKDataBaseManagerFinish)(id object, BOOL successful);

@interface KKDataBaseManager : NSObject

+ (instancetype)defaultManager;

/**
 *  插入数据
 *
 *  @param tableName 数据库表名
 *  @param records   插入的数据 @{@"key":@"value"}
 *  @param handle    操作完成
 */
- (void)insertRecordIntoTableName:(NSString*)tableName withRecords:(NSDictionary*)records finishHandle:(KKDataBaseManagerFinish)handle;

/**
 *  搜索数据
 *
 *  @param tableName 数据库表名
 *  @param condition 条件
 *  @param handle    操作完成
 */
- (void)searchRecordWithTableName:(NSString*)tableName withCondition:(NSDictionary*)condition finishHandle:(KKDataBaseManagerFinish)handle;

/**
 *  更新数据
 *
 *  @param tableName 数据库表名
 *  @param condition 条件
 *  @param records   更新的数据 @{@"key":@"value"}
 *  @param handle    操作完成
 */
- (void)updateRecordWithTableName:(NSString*)tableName withRecords:(NSDictionary*)records withCondition:(NSDictionary*)condition finishHandle:(KKDataBaseManagerFinish)handle;

/**
 *  删除数据
 *
 *  @param tableName 数据库表名
 *  @param condition 条件
 *  @param handle    操作完成
 */
- (void)removeRecordWithTableName:(NSString*)tableName withCondition:(NSDictionary*)condition finishHandle:(KKDataBaseManagerFinish)handle;

/**
 *  执行搜索SQL语句
 *
 *  @param tableName 数据库表名
 *  @param keys      结果字段
 *  @param condition 条件
 *  @param handle    操作完成
 */
- (void)executeSQLStringWithTableName:(NSString*)tableName withValueKeys:(NSArray*)keys withCondition:(NSDictionary *)condition finishHandle:(KKDataBaseManagerFinish)handle;

/**
 *  执行SQL语句
 *
 *  @param sqlString SQL语句
 *  @param keys      返回值的Keys
 *  @param handle    操作完成
 */

/**
 *  执行指定的SQL语句
 *
 *  @param sqlString SQL语句
 *  @param keys      返回值的Keys
 *
 *  @return 返回结果
 */
- (NSArray *)executeSQLString:(NSString *)sqlString withValueKeys:(NSArray *)keys;

/**
 *  使用事务执行SQL语句
 *
 *  @param sqlStrings SQL语句队列
 */
- (void)execInsertTransactionSQLStringArray:(NSArray *)sqlStrings;


/**
 *  组成SQL语句
 *
 *  @param tableName 数据库表名
 *  @param records   插入的数据 @{@"key":@"value"}
 *
 *  @return sql语句
 */
- (NSString *)sqlStringOfInsertRecordIntoTableName:(NSString*)tableName withRecords:(NSDictionary*)records sqlIdentifier:(NSString **)identifier;

@end
